from scipy.optimize import linear_sum_assignment
import numpy as np

cost = np.array([[6, 7, 11, 2],
                 [4, 5, 9, 8],
                 [3, 1, 10, 4],
                 [5, 9, 8, 2]]).T

row_ind, col_ind = linear_sum_assignment(cost)
print('row_ind:', row_ind)  # 开销矩阵对应的行索引
print('col_ind:', col_ind)  # 对应行索引的最优指派的列索引
print('cost:', cost[row_ind, col_ind])  # 提取每个行索引的最优指派列索引所在的元素，形成数组
print('cost_sum:', cost[row_ind, col_ind].sum())   # 最小开销
